//
//  YZDKnowledgeCell.m
//  YZOuterDiscxg
//
//  Created by apple on 17/8/10.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "YZDKnowledgeCell.h"
#import <YYTextAttribute.h>
#import <NSAttributedString+YYText.h>
#import <YYLabel.h>

@interface YZDKnowledgeCell ()

@property (weak, nonatomic) IBOutlet UILabel *labelContent;

@end

@implementation YZDKnowledgeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.labelContent.preferredMaxLayoutWidth = ScreenWidth - 30;
    self.labelContent.numberOfLines = 0;
    self.labelContent.backgroundColor = [YZMAppStyle colorForMain];
    self.backgroundColor = [YZMAppStyle colorForMain];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (instancetype)shareInstance{
  static  YZDKnowledgeCell *cell = nil;
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        cell = [[UINib nibWithNibName:NSStringFromClass([YZDKnowledgeCell class]) bundle:nil] instantiateWithOwner:self options:nil][0];
    });
    return cell;
}

+ (CGFloat)cellHeightForString:(NSString *)string{
    YZDKnowledgeCell *cell = [self shareInstance];
    [cell configCellWithString:string];
    [cell setNeedsUpdateConstraints];
    [cell updateConstraintsIfNeeded];
    CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    return height;
}

+ (CGFloat)cellHeightForAttibuteString:(NSMutableAttributedString *)attributeString{
    YZDKnowledgeCell *cell = [self shareInstance];
    [cell configCellWithAttibuteString:attributeString];
    [cell setNeedsUpdateConstraints];
    [cell updateConstraintsIfNeeded];
    CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    return height;
}

- (void)configCellWithString:(NSString *)string{
    self.labelContent.text = string;
}

- (void)configCellWithAttibuteString:(NSMutableAttributedString *)attributeString{
    self.labelContent.attributedText = attributeString;
}

@end
